package org.example.chatservice.repository;

import org.example.chatservice.entity.ChatRoom;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface ChatRoomRepository extends MongoRepository<ChatRoom, String> {
    List<ChatRoom> findByParticipantsContaining(String userId);
    
    @Query("{ 'type': 'PRIVATE', 'participants': { '$all': [?0, ?1] } }")
    Optional<ChatRoom> findPrivateRoom(String user1Id, String user2Id);
}